import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class LXY_Test {
    public static void main(String[] args) {
        //边
        Arc[] arcCollections=new Arc[5];
        arcCollections[0]=new Arc(new State('A'),new State('C'),'a');
        arcCollections[1]=new Arc(new State('A'),new State('B'),'b');
        arcCollections[2]=new Arc(new State('B'),new State('A'),'a');
        arcCollections[3]=new Arc(new State('C'),new State('C'),'a');
        arcCollections[4]=new Arc(new State('C'),new State('B'),'b');
        /*arcCollections[5]=new Arc(new State('D'),new State('D'),'0');
        arcCollections[6]=new Arc(new State('F'),new State('D'),'0');
        arcCollections[7]=new Arc(new State('G'),new State('D'),'0');
        arcCollections[8]=new Arc(new State('H'),new State('D'),'0');
        arcCollections[9]=new Arc(new State('X'),new State('E'),'1');
        arcCollections[10]=new Arc(new State('A'),new State('B'),'1');
        arcCollections[11]=new Arc(new State('E'),new State('E'),'1');
        arcCollections[12]=new Arc(new State('B'),new State('C'),'1');
        arcCollections[13]=new Arc(new State('C'),new State('F'),'1');
        arcCollections[14]=new Arc(new State('D'),new State('G'),'1');
        arcCollections[15]=new Arc(new State('F'),new State('F'),'1');
        arcCollections[16]=new Arc(new State('G'),new State('H'),'1');
        arcCollections[17]=new Arc(new State('H'),new State('F'),'1');*/
        //状态转换集
        List<Character> access=new ArrayList<>();
        access.add('a');
        access.add('b');
        //结束状态集
        List<State> endStateList=new ArrayList<>();
        endStateList.add(new State('A'));
        endStateList.add(new State('C'));
      /*  endStateList.add(new State('D'));
        endStateList.add(new State('F'));
        endStateList.add(new State('G'));
        endStateList.add(new State('H'));*/

        DFAGraph dfaGraph=new DFAGraph(arcCollections,5,access,new State('A'),endStateList);
        DFAMatrix dfaMatrix=MinDFA.DFAGraph_to_DFAMatrix(dfaGraph);
        for (int i = 0; i < dfaMatrix.states.size(); i++) {
            for (int j = 0; j < dfaMatrix.access.size(); j++) {
                System.out.print(dfaMatrix.accessMatrix[i][j].toString());
            }
            System.out.println();
        }
        System.out.println("得到终态和非终态集：");
        ArrayList<Set<Character>> sets=MinDFA.get_end_unend_set(dfaMatrix);
        for (int i = 0; i < sets.size(); i++) {
            System.out.println(sets.get(i).toString());
        }

        System.out.println("得到集合划分");
        sets=MinDFA.dividedSet(sets,dfaMatrix);
        for (int i = 0; i < sets.size(); i++) {
            System.out.println(sets.get(i).toString());
        }

        System.out.println("得到最小化DFA的状态转移矩阵：");
        DFAMatrix newDFAMatrix=MinDFA.reName(sets,dfaMatrix);
        System.out.println(newDFAMatrix.toString());
        for (int i = 0; i < newDFAMatrix.states.size(); i++) {
            for (int j = 0; j < newDFAMatrix.access.size(); j++) {
                System.out.print(newDFAMatrix.accessMatrix[i][j].toString());
            }
            System.out.println();
        }

        System.out.println("得到的最小化DFA:");
        DFAGraph newDFAGraph=MinDFA.DFAMatrix_to_DFAGraph(newDFAMatrix);
        System.out.println(newDFAGraph.toString());

        DFAGraph newDFAGraph2=MinDFA.DFA_minimize(dfaGraph);
        System.out.println(newDFAGraph2.toString());
    }
}
